package iterator;

import java.util.ArrayList;
import java.util.List;

public class BookShelf implements Aggregate<Book>{
    private List<Book> books = new ArrayList<>();

    @Override
    public Iterator<Book> iterator() {
        return new BookIterator(this);
    }

    // 获取元素个数
    public int size() {
        return books.size();
    }

    // 获取指定元素
    public Book get(int index) {
        return books.get(index);
    }

    // 添加元素
    public void append(Book book) {
        this.books.add(book);
    }
}
